package com.yd;

import com.doman.Teacher;
import com.doman.TeacherParent;
import com.resultmsg.BaseEnums;
import com.resultmsg.Result;
import com.resultmsg.Results;
import com.server.TeacherMapper;
import java.util.List;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

@RequestMapping(value = "/educloud")
@RestController
public class TeacherController {

    @Autowired
    private TeacherMapper teacherMapper;

    //查询老师信息
    @RequestMapping("/teacherGET")
    public Result teacherparentGET(Teacher teacher) {
        //查询用户是否是绑定用户
        List<Teacher> teacherParent1 = teacherMapper.selectByPrimaryByOpenid(teacher);
        //判断老师信息是否为空,不为空的话说明修改成功
        if (CollectionUtils.isNotEmpty(teacherParent1)) {
            return Results.successWithData(teacherParent1, BaseEnums.SUCCESS.code(), BaseEnums.SUCCESS.desc());
        }
        //若不是绑定用户的话返回不做跳转code 未绑定用户
        return Results.successWithData("",BaseEnums.FORBIDDEN.code(), BaseEnums.FORBIDDEN.desc());
    }

    //修改老师信息
    @RequestMapping("/teacherPATCH")
    public Result teacherparentPATCH(Teacher teacher) {
        //查询用户是否是绑定用户
        int teacherParent1 = teacherMapper.updateByPrimaryByOpenidUpdate(teacher);
        //判断老师信息是否为空,不为空的话说明修改成功
        if (teacherParent1 > 0) {
            return Results.successWithData(teacherParent1, BaseEnums.SUCCESS.code(), BaseEnums.SUCCESS.desc());
        }
        //若不是绑定用户的话返回不做跳转code 未绑定用户
        return Results.successWithData("",BaseEnums.FORBIDDEN.code(), BaseEnums.FORBIDDEN.desc());
    }



}
